using System.Diagnostics;
using System.Collections.Generic;
namespace System {
    public static class StringExtensions {
        public static Action<string> OutputAction = s => Debug.WriteLine(s);
        public static string Use(this string str, params object[] args) {
            return String.Format(str, args);
        }
        public static void Output(this string str, params object[] formatArgs) {
            OutputAction(str.Use(formatArgs));
        }
        public static bool IsNullOrEmpty(this string str) {
            return String.IsNullOrEmpty(str);
        }
    }
    public static class ObjectExtensions {
        public static bool IsNull<T>(this T obj) {
            return object.ReferenceEquals(null, obj);
        }
        public static bool IsNotNull<T>(this T obj) {
            return !object.ReferenceEquals(null, obj);
        }
        public static R IfNotNull<T, R>(this T obj, Func<T, R> getValue) {
            return obj.IfNotNull(getValue, default(R));
        }
        public static R IfNotNull<T, R>(this T obj, Func<T, R> getValue, R defaultVal) {
            if (obj.IsNull()) return defaultVal;
            return getValue(obj);
        }
        public static string ToSafeString<T>(this T obj) {
            return obj.IfNotNull(x => x.ToString(), String.Empty);
        }
        public static IList<T> InList<T>(this T obj) {
            return new List<T>(new []{obj});
        }
    }
}
